package com.assistant.market.modules.market.app;

import com.assistant.market.modules.market.app.cmd.MarketCodeInsertCmd;
import com.assistant.market.modules.market.app.cmd.MarketCodeListCmd;
import com.assistant.market.modules.market.domain.MarketCode;
import com.assistant.market.modules.market.domain.gateway.MarketCodeGateway;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MarketCodeService {

    @Autowired
    private MarketCodeGateway marketCodeGateway;

    public List<MarketCode> list(MarketCodeListCmd cmd) {
        return marketCodeGateway.findAllByTypeAndKeyword(cmd.getType(), cmd.getKeyword());
    }

    public void insert(MarketCodeInsertCmd cmd) {
        MarketCode marketCode = new MarketCode();
        BeanUtils.copyProperties(cmd, marketCode);
        marketCodeGateway.save(marketCode);
    }
}
